﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExpertMIS.Brokers;
using ExpertMIS.Entities;
using System.Collections;

namespace ExpertMIS.Admin.UserControl
{
    public partial class CopyRightsForm : System.Web.UI.UserControl
    {
        #region 公有方法

        public ADMCopyRightsEntity Entity
        {
            get
            {
                return ViewState["_ADMCopyRightsEntity_"] as ADMCopyRightsEntity;
            }
            set
            {
                ViewState["_ADMCopyRightsEntity_"] = value;
            }
        }

        public void LoadLastCopyRights()
        {
            // wdong，HACK
            ADMCopyRightsBroker broker = new ADMCopyRightsBroker();
            Entity = broker.GetLastCopyRights() as ADMCopyRightsEntity;

            if (Entity == null)
            {
                Entity = broker.NewEntity() as ADMCopyRightsEntity;
            }
            else
            {
                txCopyRights.Text = Entity.CopyRightsInfo;
            }
        }

        public bool SaveCopyRights()
        {
            try
            {
                ADMCopyRightsBroker broker = new ADMCopyRightsBroker();

                Entity.CopyRightsInfo = txCopyRights.Text;
                Entity.Enable = true;

                broker.SaveEntity(Entity, null);
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion
    }
}